package com.glsc.ngateway.common.base.repo.mysql.gateway.platform;

import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.RoleUrl;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.RoleUrlPK;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * 功能描述: <br>
 *
 * @author gaojc
 * @date 2020/11/24 18:59
 */
@Repository
public interface RoleUrlRepo extends JpaRepository<RoleUrl, RoleUrlPK> {

    List<RoleUrl> findByUrlId(@Param("urlId") Long urlId);

    List<RoleUrl> findByUrlIdAndRoleId(Long urlId, Long roleId);

    @Transactional
    @Modifying
    @Query(value = "insert into t_role_url(url_id, role_id) value(:authId, :roleId)", nativeQuery = true)
    void addAuthRole(@Param("authId") long authId, @Param("roleId") long roleId);

    @Transactional
    @Modifying
    @Query(value = "delete from t_role_url where url_id = :authId and role_id = :roleId", nativeQuery = true)
    void deleteAuthRole(@Param("authId") long authId, @Param("roleId") long roleId);

}
